<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

$api = app('Dingo\Api\Routing\Router');

$api->version('v1', [
    'namespace' => 'App\Http\Controllers\Api',
    'middleware' => ['cors', 'serializer:array']
], function($api) {
    $api->group([
        'middleware' => 'api.throttle',
        'limit' => config('api.rate_limits.sign.limit'),
        'expires' => config('api.rate_limits.sign.expires'),
    ], function($api) {
        // 短信验证码
        $api->post('verificationCodes', 'VerificationCodesController@store')
            ->name('api.verificationCodes.store');
        // 用户注册
        $api->post('users', 'UsersController@store')
            ->name('api.users.store');
        // 获取可用第三方登录
        $api->get('socials', 'SocialsController@index')
            ->name('api.socials.index');
        // 第三方登录
        $api->post('socials/{social_type}/authorizations/{state?}', 'AuthorizationsController@socialStore')
            ->name('api.socials.authorizations.store');

        $api->get('socials/weibo/redirect', 'AuthorizationsController@socialRedirect')
            ->name('api.socials.authorizations.rect');
        // 用户登录
        $api->post('authorizations', 'AuthorizationsController@store')
            ->name('api.authorizations.store');
        // 刷新token
        $api->put('authorizations/current', 'AuthorizationsController@update')
            ->name('api.authorizations.update');
        // 删除token
        $api->delete('authorizations/current', 'AuthorizationsController@destroy')
            ->name('api.authorizations.destroy');

        $api->group(['middleware' => 'api.auth'], function($api) {
            // 当前登录用户信息
            $api->get('user', 'UsersController@me')
                ->name('api.user.show');
            // 点赞
            $api->post('likes/{id}/{type?}', 'LikeController@store')
                ->name('api.likes.store');
            // 点赞
            $api->delete('likes/{id}/{type?}', 'LikeController@destroy')
                ->name('api.likes.destroy');
            // 收藏夹
            $api->post('collects', 'CollectsController@store')
                ->name('api.collects.store');

        });
    });
    $api->group([
        'middleware' => 'api.throttle',
        'limit' => config('api.rate_limits.explore.limit'),
        'expires' => config('api.rate_limits.explore.expires'),
    ], function($api) {
        $api->get('pictuers', 'PictuersController@index')->name('api.pictuers.index');
    });
});
